/**
 * DiggApiNet - Digg API .NET Wrapper
 * 
 * Author: Sean Hickey
 * Link: http://www.headzoo.com/digg_api_net
 * License: GPL v2 ( http://www.gnu.org/licenses/gpl.txt )
 */
using System;
using System.Collections;
using System.Text;
using System.Web;

namespace DiggApiNet
{
    public partial class DiggApi
    {
        public class ListComments : DiggApi
        {
            private const string get_all            = "http://services.digg.com/stories/comments/{0}";
            private const string get_popular        = "http://services.digg.com/stories/popular/comments/{0}";
            private const string get_upcoming       = "http://services.digg.com/stories/upcoming/comments/{0}";
            private const string get_by_story_id    = "http://services.digg.com/story/{0}/comments/{1}";
            private const string get_by_story_ids   = "http://services.digg.com/stories/{0}/comments/{1}";
            private const string get_by_user        = "http://services.digg.com/user/{0}/comments/{1}";
            private const string get_by_users       = "http://services.digg.com/users/{0}/comments/{1}";

            public DiggComments GetAll()
            {
                return GetAll(new Hashtable());
            }
            public DiggComments GetAll(Hashtable args)
            {
                string uri = String.Format(get_all, HttpBuildUrl(args));
                return new DiggComments(Request(uri));
            }

            public DiggComments GetPopular()
            {
                return GetPopular(new Hashtable());
            }
            public DiggComments GetPopular(Hashtable args)
            {
                string uri = String.Format(get_popular, HttpBuildUrl(args));
                return new DiggComments(Request(uri));
            }

            public DiggComments GetUpcoming()
            {
                return GetUpcoming(new Hashtable());
            }
            public DiggComments GetUpcoming(Hashtable args)
            {
                string uri = String.Format(get_upcoming, HttpBuildUrl(args));
                return new DiggComments(Request(uri));
            }

            public DiggComments GetByStoryId(long story_id)
            {
                return GetByStoryId(story_id, new Hashtable());
            }
            public DiggComments GetByStoryId(long story_id, Hashtable args)
            {
                string uri = String.Format(get_by_story_id, story_id, HttpBuildUrl(args));
                return new DiggComments(Request(uri));
            }

            public DiggComments GetByStoryIds(long[] story_ids)
            {
                return GetByStoryIds(story_ids, new Hashtable());
            }
            public DiggComments GetByStoryIds(long[] story_ids, Hashtable args)
            {
                string[] comb_array = new string[story_ids.Length];
                int i = 0;
                for (i = 0; i < story_ids.Length; i++) {
                    comb_array[i] = story_ids[i].ToString();
                }
                string comb_ids = HttpUtility.UrlEncode(String.Join(",", comb_array));
                string uri = String.Format(get_by_story_ids, comb_ids, HttpBuildUrl(args));
                return new DiggComments(Request(uri));
            }

            public DiggComments GetByUser(string username)
            {
                return GetByUser(username, new Hashtable());
            }
            public DiggComments GetByUser(string username, Hashtable args)
            {
                string uri = String.Format(get_by_user, username, HttpBuildUrl(args));
                return new DiggComments(Request(uri));
            }

            public DiggComments GetByUsers(string[] usernames)
            {
                return GetByUsers(usernames, new Hashtable());
            }
            public DiggComments GetByUsers(string[] usernames, Hashtable args)
            {
                string comb_users = HttpUtility.UrlEncode(String.Join(",", usernames));
                string uri = String.Format(get_by_users, comb_users, HttpBuildUrl(args));
                return new DiggComments(Request(uri));
            }
        }
    }
}
